﻿using CPPEI.WebApi;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using SER = CPPEI.ETL.Domain.Services;
using ENT = CPPEI.ETL.Domain.Entities;
using MOD = CPPEI.ETL.Domain.Models;
using VIW = CPPEI.ETL.Domain.Views;

namespace CPPEI.ETL.WebApi
{
    [CPPEI.WebApi.GetAction("ETL", "GetDataService", "1.0")]
    public class GetDataServiceAction : BaseAction<GetDataServiceParams, GetDataServiceResult>
    {
        protected override ActionResult<GetDataServiceResult> OnExecute(ActionContext context,
            SysParameters sysParameters,
            GetDataServiceParams opParams)
        {
            GetDataServiceResult result = new GetDataServiceResult();

            SER.DtSerService ser = new SER.DtSerService();

            ServiceResult<VIW.VDtSer> serResult = ser.GetDtSer(opParams.DataServiceId);

            if(serResult.IsSuccess)
            {
                result.Id = serResult.Data.Id;
                result.Name = serResult.Data.Name;
                result.TypeId = serResult.Data.TypeId;

                result.FolderId = serResult.Data.FolderId;
                result.IsEnabled = serResult.Data.IsEnabled;

                if(!string.IsNullOrEmpty(serResult.Data.Description))
                {
                    result.Description = serResult.Data.Description;
                }
                else
                {
                    result.Description = string.Empty;
                }

                return new ActionResult<GetDataServiceResult>(result);
            }
            else
            {
                return new ActionResult<GetDataServiceResult>(serResult.IsSuccess, serResult.ErrorCode, serResult.Message, null);
            }
        }
    }

    public class GetDataServiceParams
    {
        public Guid DataServiceId { get; set; }
    }

    public class GetDataServiceResult
    {
        public Guid Id { get; set; }

        public Guid FolderId { get; set; }

        public string Name { get; set; }
        public Guid TypeId { get; set; }

        public string Description { get; set; }

        /// <summary>
        /// 是否启用,true:启用,false：禁用
        /// </summary>
        public bool IsEnabled { get; set; }
    }
}
